package com.jbp.controller;

import com.jbp.model.Equip;
import com.jbp.model.EquipBag;
import com.jbp.model.EquipRoom;
import com.jbp.service.EquipBagService;
import com.jbp.service.EquipRoomService;
import com.jbp.service.EquipService;
import com.jbp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * 装备(Equip)表控制层
 * @author cc
 * @since 2020-08-31 18:43:09
 */
@Api(tags ="APP接口--Equip" )
@RestController
@RequestMapping("rest/equip")
public class EquipController {
    @Autowired
    private EquipService equipService;

    @Autowired
    private EquipBagService equipBagService;
    @Autowired
    private EquipRoomService equipRoomService;

    @ApiOperation(value="房间背景列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Equip.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/roomBgList")
    public R roomBgList(@RequestParam Integer roomId){
        return R.ok(equipService.roomBgList(roomId));
    }

    /** 设置房间背景 */
    @PostMapping("/setRoomBag")
    public R setRoomBag(@RequestBody EquipRoom equipRoom, @RequestAttribute("userId")Integer userId){
        equipRoomService.setRoomBg(equipRoom, userId);
        return R.ok();
    }

    @ApiOperation(value="个人装扮列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Equip.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/equipList")
    public R headList(@RequestParam("type") String type){
        return R.ok(equipService.equipList(type));
    }

    @ApiOperation(value="购买装备")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Equip.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @PostMapping("/buyEquip")
    public R buyEquip(@RequestParam Integer equipId, @RequestAttribute("userId")Integer userId){
        equipBagService.buyEquip(equipId, userId);
        return R.ok();
    }

    @ApiOperation(value="我的装扮列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Equip.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/myEquipList")
    public R myEquipList(@RequestParam("type") String type, @RequestAttribute("userId")Integer userId){
        return R.ok(equipBagService.equipList(type, userId));
    }

    @PostMapping("/setEquip")
    public R setEquip(@RequestParam Integer equipId, @RequestAttribute("userId")Integer userId){
        equipBagService.setEquip(equipId, userId);
        return R.ok();
    }
}